home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / matrixc.zip / MATRIX.DOC < prev    next >
Text File  |  1994-02-18  |  4KB  |  172 lines

  1. MATRIX FUNCTIONS
  2. ----------------
  3. Written by Nigel Salt for Microsoft C V5.1
  4. Nigel Salt
  5. 25 Lower Station Rd
  6. Crayford
  7. Kent
  8. DA1 3PY
  9. UK
  10.  
  11. Phone +44 322 553260
  12.  
  13. Email nao@cix.compulink.co.uk
  14.  
  15. The 3D graphics library requires a VGA display 
  16. You could convert the routines for other displays
  17. but then you would have to include aspect ratio calculations
  18. The VGA has a perfect aspect ratio
  19.  
  20. There is a book on computer graphics which is dated and based on the
  21. Spectrum computer but nevertheless very good
  22. Advanced Graphics with teh Sinclair ZX Spectrum
  23. I.O.Angell & B.J.Jones
  24. Published Macmillan Press
  25. ISBN 0 333 35050
  26.  
  27. Below are descriptions of the matrix and 3d geometry functions in
  28. this library of routines
  29.  
  30. MATRIX FUNCTIONS
  31.  
  32. /* Matrix structure */
  33. typedef struct
  34. {
  35.   int rows;
  36.   int cols;
  37.   double *block;
  38. } matrix,*matrixptr;
  39.  
  40. /*   E.G. of Matrix declaration for a 4 x 4 matrix
  41. double b4x4A[4][4]=
  42. {
  43.   6,1,6,6,
  44.   1,6,6,0,
  45.   0,3,2,1,
  46.   8,6,1,9
  47. };
  48. matrix m4x4A={4,4,&b4x4A[0][0]};
  49. */
  50.  
  51. /* Function prototypes */
  52. void mprint(matrixptr);
  53.     Print out a matrix to stdout
  54.  
  55. void smmult(matrixptr,double);
  56.     Scalar multiply a matrix by a value
  57.  
  58. int madd(matrixptr m1,matrixptr m2,matrixptr dm);
  59.     Add matrix m1 to m2 giving dm
  60.  
  61. int mmult(matrixptr m1,matrixptr m2,matrixptr dm);
  62.     Multiply matrix m1 by m2 giving dm
  63.  
  64. int mcopy(matrixptr sm,matrixptr dm);
  65.     Copy matrix sm to dm
  66.  
  67. int mtrans(matrixptr sm,matrixptr dm);
  68.     Transpose matrix sm and put result in dm
  69.  
  70. double det(matrixptr m);
  71.     Find determinant of matrix m
  72.  
  73. int minv(matrixptr sm,matrixptr dm);
  74.     Invert matrix sm and put result in dm
  75.  
  76. int nsolve(int rows,double *data);
  77.     Solve equation in N unknowns
  78.  
  79. int mid(matrixptr);
  80.     Set matrix to the identity matrix
  81.     EG 100
  82.        010
  83.        001
  84.  
  85. void mzero(matrixptr);
  86.     Set all cells of matrix to Zero
  87.  
  88. 3D FUNCTIONS
  89.  
  90. An object is defined as below
  91.  
  92. typedef struct
  93. {
  94. int points;
  95. int lines;
  96. double *pdat;
  97. int  *ldat;
  98. } object,*objectptr;
  99.  
  100. As an example a cube would be defined as follows
  101.  
  102. double cubep[8][3]=
  103. {
  104.   1,1,1,
  105.   1,1,-1,
  106.   1,-1,-1,
  107.   1,-1,1,            Each row is an x,y,z coordinate
  108.   -1,1,1,
  109.   -1,1,-1,
  110.   -1,-1,-1,
  111.   -1,-1,1
  112. };
  113.  
  114. int cubel[12][2]=
  115. {
  116.   0,1,               Each pair is a line between two of the cubep
  117.   1,2,               points
  118.   2,3,
  119.   3,0,
  120.   4,5,
  121.   5,6,
  122.   6,7,
  123.   7,4,
  124.   0,4,
  125.   1,5,
  126.   2,6,
  127.   3,7
  128. };
  129.  
  130. Finally the object definition says that the cube object has 8 points
  131. and 12 lines joining them and gives the address of the data blocks
  132. for the lines and points
  133.  
  134. object cube=
  135. {
  136.   8.0,12.0,&cubep[0][0],&cubel[0][0]
  137. };
  138.  
  139.  
  140. /* function prototypes */
  141. int tran3(matrixptr m,double tx,double ty,double tz);
  142.   Translate matrix m by tx ty tz
  143.  
  144. int scale3(matrixptr m,double sx,double sy,double sz);
  145.   Scale matrix m by sx sy sz
  146.  
  147. int rot3(matrixptr m,double theta,int axis);
  148.     Rotate matrix m by theta radians about axis
  149.     (1=x,2=y,3=z)
  150.     
  151. double angle(double ax,double ay);
  152.     Return arctangent of ax/ay in radians
  153.  
  154. void p3mult(double *,matrixptr);
  155.     Multiply a point by a matrix
  156.  
  157. int objcop(objectptr s,objectptr d);
  158.     Copy object pointed to by s to destination pointed to by d
  159.  
  160. int init3d(void);
  161.     Set VGA graphics mode etc
  162.  
  163. void objtran(objectptr o,matrixptr m);
  164.     translate an object by matrix m
  165.  
  166. void objprin(objectptr o);
  167.     print out an object definition
  168.  
  169. void objdraw(objectptr o);
  170.     draw the object on the screen
  171.  
  172.